package com.rub.android.ui.activity

import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.rub.android.R


class FragmentActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_fragment)

        val wm = getSystemService(WINDOW_SERVICE) as? WindowManager


        val width = wm!!.defaultDisplay.width
        val height = wm!!.defaultDisplay.height
        if (height > width) {
          //  replaceFragment(Fragement1())
        } else {
            //replaceFragment(Fragement2())
        }

    }

    private fun replaceFragment(fragment: Fragment) {

        val fragmentManager = supportFragmentManager
        fragmentManager.beginTransaction()
            .replace(android.R.id.content, fragment)
                //此行代码是为了操作多少次事件，当回退键就操作多少次
            .addToBackStack(null)
            .commitAllowingStateLoss()


    }
}